//package cn.tth.test.rabbitmq;
//
//import cn.tth.test.model.proxy.CglibProxy;
//import com.alibaba.fastjson.JSON;
//import lombok.Data;
//import lombok.experimental.Accessors;
//import org.springframework.amqp.core.*;
//import org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor;
//import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils;
//import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
//import org.springframework.amqp.rabbit.connection.ConnectionFactory;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.config.SingletonBeanRegistry;
//import org.springframework.beans.factory.support.BeanDefinitionRegistry;
//import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
//import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//
//import java.util.HashMap;
//import java.util.Map;
//
//
//@Configuration
//public class MqConfig {
////
////    @ConditionalOnMissingBean(name = RabbitListenerConfigUtils.RABBIT_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
////    @Primary
////    @Bean(name = RabbitListenerConfigUtils.RABBIT_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
////    RabbitListenerAnnotationBeanPostProcessor internalRabbitListenerAnnotationProcessor() {
////
////        MyRabbitListenerAnnotationBeanPostProcessor processor = new MyRabbitListenerAnnotationBeanPostProcessor();
////        return processor;
////    }
//
//
//
//
//    public static final String 生产者Exchange = "mode:test:exchange";
//    public static final String 生产者RoutingKey = "mode:test:routingKey";
//
//    public static final String 死信队列Queue = "mode:declare:queue";
//    public static final String 死信队列交换机 = "mode:declare:exchange";
//    public static final String 死信队列BindingKey = "mode:declare:routingKey";
//
//    public static final String 延时队列Queue = "mode:delay:queue";
//
//    /*----------------------------------------------------------------------------------*/
//    public static final String 生产者RoutingKey_1 = "mode:test:routingKey:1";
//    public static final String 生产者Queue_1 = "mode:test:queue:1";
//
//    /*
//     * 创建延时队列 -----------------------------------------
//     * 队列不能有消费者
//     * 队列绑定死信的交换机,bindingKey
//     *
//     */
//    @Bean
//    public Queue queue(){
//        Map<String,Object> map = new HashMap<>();
//        map.put("x-dead-letter-exchange",MqConfig.死信队列交换机);
//        map.put("x-dead-letter-routing-key",MqConfig.死信队列BindingKey);
//        return new Queue(延时队列Queue,true,false,false,map);
//    }
//    @Bean
//    public Binding binding(){
//        return BindingBuilder.bind(queue()).to(topicExchange()).with(生产者RoutingKey);
//    }
//    @Bean
//    public TopicExchange topicExchange(){
//        return new TopicExchange(生产者Exchange);
//    }
//    /*
//     * 创建延时队列 -----------------------------------------
//     */
//
//    @Bean
//    public RetryMq retryMq(RabbitTemplate rabbitTemplate){
//        return new RetryMq(rabbitTemplate);
//    }
//
//
//    public static class RetryMq{
//
//        private RabbitTemplate rabbitTemplate;
//
//        RetryMq(RabbitTemplate rabbitTemplate){
//            this.rabbitTemplate = rabbitTemplate;
//        }
//
//        public void execute(String exchange, String routingKey, Object message,int... spacing){
//
//            TransformMessage transformMessage = new TransformMessage();
//            transformMessage.setSpacing(spacing);
//            transformMessage.setMessage(message);
//            transformMessage.setSize(spacing.length);
//            transformMessage.setCurrentSubscript(0);
//            transformMessage.setExchange(exchange);
//            transformMessage.setRoutingKey(routingKey);
//
//            rabbitTemplate.convertAndSend(exchange,routingKey, JSON.toJSONString(transformMessage),e -> {
//                e.getMessageProperties().setExpiration(String.valueOf(spacing[0]));
//                return e;
//            });
//        }
//    }
//
//    @Data
//    @Accessors(chain = true)
//    public static class TransformMessage{
//        /**
//         * 间隙
//         */
//        private int[] spacing;
//        /**
//         * 消息
//         */
//        private Object message;
//        /**
//         * 次数
//         */
//        private int size;
//        /**
//         * 当前下标
//         */
//        private int currentSubscript;
//
//        /**
//         * 交换
//         */
//        private String exchange;
//
//        /**
//         * 路由的关键
//         */
//        private String routingKey;
//    }
//}
